#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import json

app_id="5b0e6935bea7c049a64210b0"
base_url="https://robot-lib.kangfuzi.com/"


session={}



def get_session():
    global session
    url="https://robot-lib.kangfuzi.com/?app_id={app_id}&action=get_settings"
    url=url.format(app_id=app_id)
    res=requests.get(url)
    if res.status_code==200:
        ss=res.text
        print(ss)
        sessions=json.loads(ss)
        if "status" in sessions:
            sessions.pop("status")
            sessions["app_id"] = app_id
        session=sessions;
        print(session)
    else:
        print(res.status_code)



def init_dialog():
    session["action"]="init_dialog"
    res=requests.get(base_url,params=session)
    if res.status_code==200:
        print(res.text)
        q1=json.loads(res.text)
        session["qid"]=q1.get("qid")
    else:
        print(res.status_code)


def answer_q(answer):
    session["action"]="upload_answer"
    session["answer"]=answer
    # print(session)
    res=requests.get(base_url,params=session)
    if res.status_code==200:

        q1=json.loads(res.text)
        data=q1.get("return_json")
        print(data)
        session["qid"]=q1.get("qid")
    else:
        print(res.status_code)

def end_session():
    session["action"]="force_to_end"
    # print(session)
    res=requests.get(base_url,params=session)
    if res.status_code==200:
        print(res.text)
    else:
        print(res.status_code)

get_session()
init_dialog()
answer_q("我喉咙痛")
answer_q("我是男生")
answer_q("我十五岁了")
answer_q("我头痛")
answer_q("很好")
answer_q("没有")
answer_q("没有")
answer_q("没有")
# end_session()



